% Copyright (C) 2014-19 Benjamin Born and Johannes Pfeifer 
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% For a copy of the licencse,
% see <http://www.gnu.org/licenses/>.

function Figure_A2
if ~isfolder('Results')
    mkdir('.','Results');
end
addpath('../Auxiliary_Files')

load('../data_array_for_regression_stacked_by_variable_CDS_new.mat')
fontsize=8;

timeline=data_array_for_regression_stacked_by_variable(:,1,pos.timeline);
plot_iter=1;
for country_iter=1:size(data_array_for_regression_stacked_by_variable,2)
    if data_array_for_regression_stacked_by_variable(timeline==2012.25,country_iter,pos.euro_country) && data_array_for_regression_stacked_by_variable(timeline==2010,country_iter,pos.monetary_union_member)==1
            spread_change(plot_iter)=data_array_for_regression_stacked_by_variable(timeline==2012.25,country_iter,pos.spread_end_quarter)...
                -data_array_for_regression_stacked_by_variable(timeline==2010,country_iter,pos.spread_end_quarter);
            g_change(plot_iter)=data_array_for_regression_stacked_by_variable(timeline==2012.25,country_iter,pos.g_real)...
                -data_array_for_regression_stacked_by_variable(timeline==2010,country_iter,pos.g_real);
        names{plot_iter}=country_header{country_iter};
        plot_iter=plot_iter+1;
    end
end

x_var=-g_change'*100;
y_var=spread_change';
corr(x_var(~any(isnan([x_var y_var]),2)),y_var(~any(isnan([x_var y_var]),2)))

figure
subplot(2,1,1)
lscatter(x_var(~any(isnan([x_var y_var]),2)),y_var(~any(isnan([x_var y_var]),2)),names(~any(isnan([x_var y_var]),2)),'Marker','.','MarkerEdgeColor','red','MarkerFaceColor','red','HorizontalAlignment','left','VerticalAlignment','top','FontSize',8)
xlabel('Reduction of government consumption','FontSize',fontsize)
ylabel('Change of default premium','FontSize',fontsize)
ylim([-1.5 8])
xlim([0 12.5])
set(gca,'FontSize',fontsize)
print('Results/Euro_Spreads_spending_correlation','-depsc2')